import 'package:flutter/material.dart';
import 'package:xingsu/page/mine/viewModel/mine_viewmodel.dart';
import 'package:xingsu/res/theme.dart';
import 'package:xingsu/util/use_preferences.dart';
import 'package:get/get.dart';

class ThemePage extends StatefulWidget {
  @override
  State<ThemePage> createState() => _ThemePageState();
}

class _ThemePageState extends State<ThemePage> {
  final List<String> _list = <String>['跟随系统', '关闭', '开启'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("暗黑模式"),
      ),
      body: ListView.separated(
        itemCount: _list.length,
        separatorBuilder: (_, __) => const Divider(),
        itemBuilder: (_, int index) {
          return InkWell(
            onTap: () {
              ThemeUtil.setThemeMode(index);
              MineViewModel _viewModel = Get.find();
              _viewModel.getThemeModelDesc();
              setState(() {});
            },
            child: Container(
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              height: 50.0,
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Text(_list[index]),
                  ),
                  Opacity(
                    opacity: UserPreferences.getThemeMode() == index ? 1 : 0,
                    child: const Icon(Icons.done, color: Colors.blue),
                  )
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
